var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/WFDynamicNodeUserWin.tsx
var WFDynamicNodeUserWin_exports = {};
__export(WFDynamicNodeUserWin_exports, {
  WFDynamicNodeUserWin: () => WFDynamicNodeUserWin,
  WFDynamicNodeUserWinFooter: () => WFDynamicNodeUserWinFooter
});
module.exports = __toCommonJS(WFDynamicNodeUserWin_exports);
var import_react = __toESM(require("react"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_util2 = require("./util");
var import_WFOrgtree = require("./WFOrgtree");
var TabKeys = ["", "first", "second", "third", "four", "five"];
var tableProps = {
  rowSelected: true,
  headerHeight: 32,
  rowHeight: 30,
  style: { border: "1px solid var(--border-color-split, #f0f0f0)", borderTop: 0 }
};
var columnProps = {
  sortable: false,
  resizable: false,
  columnSort: false,
  tooltip: true
};
var defaultPagination = { pageSize: 15, height: 32, showQuickJumper: false, align: "left" };
var tabTitle = (title) => /* @__PURE__ */ import_react.default.createElement("span", { style: { padding: "0 6px" } }, title);
function WFDynamicNodeUserWin(props) {
  const {
    radioItems = [1, 3, 4, 5],
    //暂时隐藏常用人员
    loginInfo = {},
    selectedData = [],
    otherInfo = { type: "all", orgList: [] },
    isMulti = true,
    cancelBack,
    callBack
  } = props;
  const [searchValue, setSearchValue] = (0, import_react.useState)("");
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const resultColumns = (0, import_react.useMemo)(() => {
    return [
      {
        ...columnProps,
        header: import_util2.NGLang.userNo,
        flex: 1,
        dataIndex: "userNo"
      },
      {
        ...columnProps,
        header: import_util2.NGLang.userName,
        flex: 1,
        dataIndex: "userName"
      },
      {
        ...columnProps,
        header: import_util2.NGLang.userOrg,
        flex: 1,
        dataIndex: "belongOrgName"
      },
      {
        ...columnProps,
        header: import_util2.NGLang.userDept,
        flex: 1,
        dataIndex: "belongDeptName"
      }
    ];
  }, []);
  const tabs = (0, import_react.useMemo)(() => {
    const tabItems = [];
    radioItems.includes(1) && tabItems.push({ key: TabKeys[1], title: "待选人员" });
    radioItems.includes(3) && tabItems.push({
      key: TabKeys[3],
      title: "本单元",
      idList: loginInfo.cuid,
      type: "cu"
    });
    radioItems.includes(4) && loginInfo.bqid && tabItems.push({
      key: TabKeys[4],
      title: "本板块",
      type: "bu",
      idList: loginInfo.bqid
    });
    radioItems.includes(5) && tabItems.push({
      key: TabKeys[5],
      title: "其他人员",
      type: otherInfo.type,
      idList: otherInfo.orgList.join()
    });
    return tabItems;
  }, []);
  const [activeTab, setActiveTab] = (0, import_react.useState)({ key: tabs[0].key, type: tabs[0].type, idList: tabs[0].idList });
  const setActiveKey = (0, import_util.useRefCallback)((activeKey) => {
    const { key, type, idList } = tabs.find((tab) => tab.key === activeKey);
    setActiveTab({ key, type, idList });
    mCtx.ins.notify(activeKey, "activeKey");
  });
  const getActiveTable = (0, import_util.useRefCallback)(() => {
    return import_util.iup.getCmp(`${activeTab.key}WfTable`).getApi();
  });
  const getResultTable = (0, import_util.useRefCallback)(() => {
    return import_util.iup.getCmp(`resultWfTable`).getApi();
  });
  const toResult = (0, import_util.useRefCallback)((data) => {
    if (!isMulti) {
      return;
    }
    const resultTable = getResultTable();
    const selected = [];
    const resultKeys = resultTable.getRows().map((r) => r.id);
    data.forEach((sd) => {
      if (!resultKeys.includes(sd.id)) {
        selected.push(resultTable.copyRow(sd));
      }
    });
    resultTable.addRows(selected).then();
  });
  const toRemove = (0, import_util.useRefCallback)((indexes) => {
    if (indexes === void 0) {
      getResultTable().setDataSource([]);
    } else {
      getResultTable().deleteRows(indexes);
    }
  });
  const invokeOkHandler = (0, import_util.useRefCallback)(async () => {
    var _a;
    if (!callBack) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.noCallBack);
      return;
    }
    const data = isMulti ? getResultTable().getRows() : getActiveTable().getSelectedData();
    console.log(data, "选人框返回", isMulti);
    if (data.length === 0) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.hasNoSelectData);
      return;
    }
    await callBack(isMulti ? data : data[0]);
    (_a = mCtx.ins) == null ? void 0 : _a.destroy();
  });
  const invokeCancelHandler = (0, import_util.useRefCallback)(async () => {
    var _a;
    await (cancelBack == null ? void 0 : cancelBack());
    (_a = mCtx.ins) == null ? void 0 : _a.destroy();
  });
  const getTabContent = (0, import_util.useRefCallback)((tabKey) => {
    switch (tabKey) {
      case "first":
        return /* @__PURE__ */ import_react.default.createElement(
          FirstTable,
          {
            tabKey: "first",
            activeKey: activeTab.key,
            parentProps: props,
            searchValue,
            toResult
          }
        );
      case "second":
        return /* @__PURE__ */ import_react.default.createElement(
          SecondTable,
          {
            tabKey: "second",
            activeKey: activeTab.key,
            parentProps: props,
            searchValue,
            toResult
          }
        );
      case "third":
        return /* @__PURE__ */ import_react.default.createElement(
          ThirdTable,
          {
            tabKey: "third",
            activeKey: activeTab.key,
            parentProps: props,
            searchValue,
            toResult
          }
        );
      default:
        return /* @__PURE__ */ import_react.default.createElement("div", null, "No Content");
    }
  });
  const onRow = (0, import_util.useRefCallback)((rowIndex) => {
    return {
      onDoubleClick() {
        toRemove(rowIndex);
      }
    };
  });
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeOkHandler,
      invokeCancelHandler,
      getActiveTable
    });
  }, [activeTab]);
  (0, import_react.useEffect)(() => {
    if (isMulti && (selectedData == null ? void 0 : selectedData.length)) {
      getResultTable().addRows(selectedData).then();
    }
  }, []);
  return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, { direction: "row", style: { height: 400, padding: "0 5px" } }, /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Tabs,
    {
      className: "fit-height ng-compact-tab",
      size: "small",
      tabBarGutter: 5,
      activeKey: activeTab.key,
      onChange: setActiveKey,
      tabBarExtraContent: /* @__PURE__ */ import_react.default.createElement(import_baseComponent.Search, { allowClear: true, placeholder: import_util2.NGLang.seachEmptyText, size: "small", onSearch: setSearchValue })
    },
    tabs.map((tab) => /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Tabs.Option, { tab: tabTitle(tab.title), key: tab.key, children: getTabContent(tab.key) }))
  )), isMulti && /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.BaseHelp.MultipleButtons,
    {
      getActiveTable,
      getResultTable,
      addResult: toResult,
      removeResult: toRemove
    }
  ), isMulti && /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 220, paddingTop: 7 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      checkbox: true,
      style: { ...tableProps.style, marginTop: 0 },
      columns: resultColumns,
      id: "resultWfTable",
      onRow
    }
  )));
}
function WFDynamicNodeUserWinFooter({ radioItems }) {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const [loading, setLoading] = (0, import_util.useRefState)(false);
  const [tabKey, setTabKey] = (0, import_util.useRefState)(TabKeys[radioItems[0]]);
  const btnClick = async () => {
    var _a, _b, _c;
    const insApi = mCtx.ins.getApi();
    const selectedData = insApi.getActiveTable().getSelectedData();
    if (selectedData.length > 0) {
      setLoading(true);
      if (tabKey === TabKeys[2]) {
        const result = await import_util.iup.request.body({
          url: `SUP/RichHelp/DeleteCommonUseData`,
          data: { helpid: "fg3_user_work", codeValue: selectedData.map((d) => d.userId).join() }
        });
        if (result.code === 0) {
          insApi.getActiveTable().refreshData();
          import_functionalComponent.message.success(import_util2.NGLang.removeCommonSuccess);
        } else if (result.message) {
          import_functionalComponent.message.error(result.message);
        }
      } else {
        const result = await import_util.iup.request.body({
          url: `SUP/RichHelp/SaveCommonUseData`,
          data: { helpid: "fg3_user_work", codeValue: selectedData.map((d) => d.userId).join() }
        });
        if (result.code === 0) {
          (_c = (_b = (_a = import_util.iup.getCmp(`${TabKeys[2]}WfTable`)) == null ? void 0 : _a.getApi()) == null ? void 0 : _b.refreshData) == null ? void 0 : _c.call(_b);
          import_functionalComponent.message.success(import_util2.NGLang.addCommonSuccess);
        } else if (result.message) {
          import_functionalComponent.message.error(result.message);
        }
      }
      setLoading(false);
    } else {
      import_functionalComponent.message.info(import_util2.NGLang.select);
    }
  };
  (0, import_react.useEffect)(() => {
    if (radioItems.includes(2)) {
      return mCtx.ins.subscribe((activeKey) => {
        setTabKey(activeKey);
      }, "activeKey");
    }
  }, [radioItems]);
  if (!radioItems.includes(2)) {
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { flex: 1 } }, /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Button, { size: "small", loading, style: { marginLeft: 5 }, onClick: btnClick }, tabKey !== TabKeys[2] ? import_util2.NGLang.AddCommonUse : import_util2.NGLang.DelCommonUse));
}
var FirstTable = import_react.default.memo(
  ({ tabKey, parentProps, searchValue, toResult }) => {
    const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
    const { isMulti = true, todoData = [] } = parentProps;
    const columns = (0, import_react.useMemo)(() => {
      return [
        {
          ...columnProps,
          header: import_util2.NGLang.userNo,
          flex: 2,
          dataIndex: "userNo"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userName,
          flex: 2,
          dataIndex: "userName"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userDept,
          flex: 3,
          dataIndex: "belongOrgName"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userOrg,
          flex: 3,
          dataIndex: "belongDeptName"
        }
      ];
    }, []);
    const dataSource = (0, import_react.useMemo)(() => {
      return searchValue ? todoData.filter(
        (row) => {
          var _a, _b, _c, _d;
          return ((_a = row.userName) == null ? void 0 : _a.indexOf(searchValue)) > -1 || ((_b = row.userNo) == null ? void 0 : _b.indexOf(searchValue)) > -1 || ((_c = row.orgName) == null ? void 0 : _c.indexOf(searchValue)) > -1 || ((_d = row.deptName) == null ? void 0 : _d.indexOf(searchValue)) > -1;
        }
      ) : todoData;
    }, [searchValue]);
    const onRow = (0, import_util.useRefCallback)((rowIndex, table) => {
      return {
        onDoubleClick() {
          if (isMulti) {
            toResult == null ? void 0 : toResult([table.getRow(rowIndex)]);
          } else {
            mCtx.ins.getApi().invokeOkHandler().then();
          }
        }
      };
    });
    return /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        id: `${tabKey}WfTable`,
        ...tableProps,
        checkbox: isMulti,
        onRow,
        columns,
        dataSource
      }
    );
  },
  (p, n) => {
    return n.tabKey !== n.activeKey || import_util.iup.isPropsEqual(p, n);
  }
);
var SecondTable = import_react.default.memo(
  ({ tabKey, parentProps, searchValue, toResult }) => {
    const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
    const { isMulti = true } = parentProps;
    const columns = (0, import_react.useMemo)(() => {
      return [
        {
          ...columnProps,
          header: import_util2.NGLang.userNo,
          flex: 2,
          dataIndex: "userNo"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userName,
          flex: 2,
          dataIndex: "userName"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userDept,
          flex: 3,
          dataIndex: "belongOrgName"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userOrg,
          flex: 3,
          dataIndex: "belongDeptName"
        }
      ];
    }, []);
    const defaultResponse = (0, import_util.useRefCallback)((res) => ({
      total: res.totalRows,
      record: res.Record.map((data) => {
        return {
          userId: data.value,
          userNo: data.value,
          userName: data.label,
          deptName: data.deptname,
          orgName: data.orgname
        };
      })
    }));
    const requestList = (0, import_react.useMemo)(() => {
      return async ({ pageIndex, pageSize }) => {
        return await import_util.iup.request.body({
          url: "SUP/RichHelp/GetCommonUseList?helpid=fg3_user_work&ORMMode=false",
          data: {
            page: pageIndex - 1,
            usePY: true,
            query: searchValue,
            start: (pageIndex - 1) * pageSize,
            limit: pageSize
          }
        });
      };
    }, [searchValue]);
    const onRow = (0, import_util.useRefCallback)((rowIndex, table) => {
      return {
        onDoubleClick() {
          if (isMulti) {
            toResult == null ? void 0 : toResult([table.getRow(rowIndex)]);
          } else {
            mCtx.ins.getApi().invokeOkHandler().then();
          }
        }
      };
    });
    return /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        id: `${tabKey}WfTable`,
        ...tableProps,
        checkbox: isMulti,
        onRow,
        request: requestList,
        response: defaultResponse,
        pagination: defaultPagination,
        columns
      }
    );
  },
  (p, n) => {
    return n.tabKey !== n.activeKey || import_util.iup.isPropsEqual(p, n);
  }
);
var ThirdTable = import_react.default.memo(
  ({ tabKey, parentProps, searchValue, toResult }) => {
    const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
    const { isMulti = true } = parentProps;
    const columns = (0, import_react.useMemo)(() => {
      return [
        {
          ...columnProps,
          header: import_util2.NGLang.userNo,
          flex: 1,
          dataIndex: "userNo"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userName,
          flex: 1,
          dataIndex: "userName"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userOrg,
          flex: 1,
          dataIndex: "belongOrgName"
        },
        {
          ...columnProps,
          header: import_util2.NGLang.userDept,
          flex: 1,
          dataIndex: "belongDeptName"
        }
      ];
    }, []);
    const defaultResponse = (0, import_util.useRefCallback)((res) => {
      var _a;
      if (res.code === 0) {
        return {
          total: res.data.total || 0,
          record: ((_a = res.data.list) == null ? void 0 : _a.map((data) => {
            return { ...data, userNo: data.userNo };
          })) || []
        };
      } else {
        return {
          total: 0,
          record: []
        };
      }
    });
    const requestList = (0, import_util.useRefCallback)(async ({ pageIndex, pageSize, belongOrg }) => {
      return await import_util.iup.request.body({
        url: "/basedata/user/queryUserList",
        data: { pageNum: pageIndex, pageSize, belongOrg, query: searchValue }
      });
    });
    (0, import_util.useIUPEffect)(
      () => {
        import_util.iup.getCmpApi(`${tabKey}WfTable`).query();
      },
      [searchValue],
      false
    );
    const onRow = (0, import_util.useRefCallback)((rowIndex, table) => {
      return {
        onDoubleClick() {
          if (isMulti) {
            toResult == null ? void 0 : toResult([table.getRow(rowIndex)]);
          } else {
            mCtx.ins.getApi().invokeOkHandler().then();
          }
        }
      };
    });
    const onTreeDataLoad = (0, import_util.useRefCallback)((nodes) => {
      nodes.push({
        value: "nodeptid",
        title: import_util2.NGLang.noDeptData,
        isLeaf: true,
        id: 0,
        key: "nodeptid",
        OCode: "nodeptid"
      });
      return nodes;
    });
    const onTreeSelectCallback = (0, import_util.useRefCallback)((keys, nodes) => {
      console.log(nodes, "nodesnodes");
      import_util.iup.getCmpApi(`${tabKey}WfTable`).setExtraParam({
        belongOrg: nodes[0].code
      });
    });
    const params = (0, import_react.useMemo)(() => {
      return { orgattr: "18", isRight: false };
    }, []);
    return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, { direction: "row", style: { height: "100%" } }, /* @__PURE__ */ import_react.default.createElement(
      import_util.Layout.Slider,
      {
        style: { width: 180, marginRight: 5, border: "1px solid var(--border-color-split, #f0f0f0)", borderTop: 0 }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_WFOrgtree.WFOrgtree,
        {
          params,
          defaultSelectedFirstNode: true,
          onSelectedChange: onTreeSelectCallback,
          dataLoad: onTreeDataLoad
        }
      )
    ), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        id: `${tabKey}WfTable`,
        ...tableProps,
        autoLoad: false,
        checkbox: isMulti,
        onRow,
        request: requestList,
        response: defaultResponse,
        pagination: defaultPagination,
        columns
      }
    )));
  },
  (p, n) => {
    return n.tabKey !== n.activeKey || import_util.iup.isPropsEqual(p, n);
  }
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WFDynamicNodeUserWin,
  WFDynamicNodeUserWinFooter
});
